package com.ucap.weking.guangan.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ucap.weking.guangan.R;
import com.ucap.weking.guangan.bean.ItemListOnlineBean;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by weking on 2017/11/13.
 */

public class LiveOnlineAdapter extends BaseAdapter {
    ArrayList<ItemListOnlineBean.RowsBean> mData;

    public LiveOnlineAdapter(ArrayList<ItemListOnlineBean.RowsBean> mData) {
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public ItemListOnlineBean.RowsBean getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_live_online, null);
            holder = new Holder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        ItemListOnlineBean.RowsBean item = getItem(position);
        Glide.with(parent.getContext())
                .load(item.getPIC())
                .into(holder.ivImage);
        holder.tvTitle.setText(item.getTITLE());
        holder.tvTimer.setText(item.getTIME());
        holder.tvGuest.setText(item.getGUEST());
        return convertView;
    }

    class Holder {
        @InjectView(R.id.iv_image)
        ImageView ivImage;//图片
        @InjectView(R.id.tv_title)
        TextView tvTitle;//主题
        @InjectView(R.id.tv_timer)
        TextView tvTimer;//访谈时间
        @InjectView(R.id.tv_guest)
        TextView tvGuest;//嘉宾

        public Holder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
